﻿using Engine;
using Engine.Graphics;
using Game;

namespace SAGhoul.Blocks
{
	public class BizarreMetalBlock : Block
    {
        public BlockMesh m_standaloneBlockMesh = new();
        readonly Game.Random m_random = new();
        Texture2D m_texture;
        public override void Initialize()
        {
            SAGhoulsManager.Rotation = new Vector2(m_random.Float(0, 2f * MathUtils.PI), m_random.Float(0, 2f * MathUtils.PI));
            Model model = ContentManager.Get<Model>("Models/Chunk");
            m_texture = ContentManager.Get<Texture2D>("Textures/BizarreMetal");
            Matrix matrix = BlockMesh.GetBoneAbsoluteTransform(model.Meshes[0].ParentBone) * Matrix.CreateRotationX(SAGhoulsManager.Rotation.X) * Matrix.CreateRotationZ(SAGhoulsManager.Rotation.Y);
            m_standaloneBlockMesh.AppendModelMeshPart(model.Meshes[0].MeshParts[0], matrix, makeEmissive: true, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White);
            m_standaloneBlockMesh.TransformTextureCoordinates(Matrix.CreateScale(16f));
            base.Initialize();
        }

        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
        }

        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, m_texture, Color.White, 2f * size, ref matrix, environmentData);
        }
    }
}
